<%@ page import="com.gpay.erp.core.system.bean.SysUser" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<script src="<%=request.getContextPath() %>/resources/js/purchase/paymentManage.js"
        type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/resources/js/purchase/paymentApS.js"
        type="text/javascript"></script>
<script src="<%=request.getContextPath() %>/resources/js/purchase/paymentApAdd.js"
        type="text/javascript"></script>
<script>
    var selectedRows;
    $(function () {
        $('#appAmount').numberbox({
            precision:2,groupSeparator:',',decimalSeparator:'.',
            formatter: function (value) {
                return formatNum(value);
            }
        });
        $('#realAmount').numberbox({
            precision:2,groupSeparator:',',decimalSeparator:'.',
            formatter: function (value) {
                return formatNum(value);
            }
        });
        var paymentApId = $("#paymentApId").text();
        if (paymentApId) {
            $('#memberNoDiv').html("<label>供应商代码:</label><input id='memberNo' name='f_providerId' data-options='required:true' readonly style='width:90px' />");
            $('#shifujine').show();
            initSelect($('#payMethod'), payMethodArray);
            $("#cancelPaFunction").click(function () {
                changeStatus("/payment/saveChangeStatusApplicationSub.html", paymentApId, "cancelApp", refreshPaymentPage);
            });
            $("#cancelPaSubmitFunction").click(function () {
                changeStatus("/payment/saveChangeStatusApplicationSub.html", paymentApId, "cancelcommitApp", refreshPaymentPage);
            });
            $("#handlePaSubmitFunction").click(function () {
                changeStatus("/payment/saveChangeStatusApplicationSub.html", paymentApId, "commitApp", refreshPaymentPage);
            });

            //获取子项列表
            $.ajax({
                type: "post",
                data: {'id': paymentApId},
                dataType: "json",
                url: getContextPath() + "/payment/selectPaidApplicationSub.html",
                before: function () {
                    parent.$.messager.progress({
                        title: '提示',
                        text: '数据处理中，请稍后....'
                    });
                },
                success: function (data) {
                    parent.$.messager.progress('close');
                    if (data && isSuccess(data.result)) {
                        refreshPaymentPage(data);
                        //修改保存按钮
                        $('#editPaFunction').click(function () {
                            calculatePaymentToTop();
                            var isValid = showValidteMessage(validatePaymentTopSubs(true))
                                    && showValidteMessage(validatePaymentBottomSubs(
                                            preparePaymentSubmitPostData(true).paidApplicationSubList));
                            if (isValid) {
                                postAjax("/payment/savePaidApplicationSub.html",
                                        JSON.stringify(preparePaymentSubmitRealPostData(true)),
                                        getPaymentDetail, {async: false});


                            } else {
                                return isValid;
                            }
                        });
                    } else {
                        commonError(data.result, data.message);
                    }
                },
                timeout: 1000,
                error: function (result) {
//			internalError();
                    templateInternalError(result.responseText);
                    parent.$.messager.progress('close');
                }
            });
        } else {
            initComboDataGrid("/suppliersController/selectList.html", $("#memberNo"), getSupplierComboGridOptions());
            initSelectAjax("/global/payMethod.html", $('#payMethod'));

            initDataGridNoPager($('#subItem'), getPaymentSubOptions());

            $('#addFunction').click(function () {
                calculatePaymentToTop();
                var isValid = showValidteMessage(validatePaymentTopSubs()) && showValidteMessage(validatePaymentBottomSubs(preparePaymentSubmitPostData().paidApplicationSubList));
                if (isValid) {
                    postAjax("/payment/savePaidApplicationSub.html", JSON.stringify(preparePaymentSubmitRealPostData()),
                            getPaymentDetail, {async: false});
                } else {
                    return isValid;
                }
            });

            $('#addAndSaveFunction').click(function () {
                calculatePaymentToTop();
                var isValid = showValidteMessage(validatePaymentTopSubs()) && showValidteMessage(validatePaymentBottomSubs(preparePaymentSubmitPostData().paidApplicationSubList));
                if (isValid) {
                    postAjax("/payment/saveCommitPaidApplicationSub.html", JSON.stringify(preparePaymentSubmitRealPostData()),
                            getPaymentDetail, {async: false});

                } else {
                    return isValid;
                }
            });
            //新增顶部细节
//            $('#cancelSettlementCompletion').hide();
//            $('#settlementCompletion').hide();
//            $('#cancelGoodsFinish').hide();
//            $('#goodsFinish').hide();
            $('#paidStarttime').datebox({
                required: true,
                editable: false
            });
            $('#paidStarttime').datebox("setValue", myformatter(new Date()));
            $('#paidStatus').val('新增');
//            addContract();
//            calculateToTop();
//            calculatePaymentToTop();
        }
    });

</script>
<%--申请单号、申请状态、供应商代码、供应商名称、申请金额、支付方式、申请日期、申请人、备注--%>
<var hidden="hidden" id="paymentApId">${paymentApId}</var>
<var hidden="hidden" id="appOld"></var>
<div class="easyui-layout" data-options="fit : true,border : false">
    <div data-options="region:'north',title:'付款申请',border : false" style="height: 140px; overflow: hidden;">
        <form id="searchForm-small">
            <div class="mLeft60">
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>申请单号:</label>
                        <input id="paidAppNumber" name="paidAppNumber" readonly>
                        </input>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>申请状态:</label>
                        <input id="paidStatus" name="paidStatus" class="easyui-input" readonly/>
                    </div>
                    <div class="fLeft label-handsome" id="memberNoDiv">
                        <label class="redSharp">* 供应商代码:</label>
                        <select id="memberNo" name="f_providerId" data-options="required:true" style="width:90px">
                        </select>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>供应商名称:</label>
                        <input id="providerName" name="providerName" class="easyui-input" readonly/>
                    </div>
                </div>
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>申请金额:</label>
                        <input id="appAmount" name="appAmount" readonly>
                        </input>
                    </div>
                    <div class="fLeft label-handsome " id="shifujine" hidden="hidden">
                        <label>实付金额:</label>
                        <input id="realAmount" name="realAmount" readonly>
                        </input>
                    </div>
                    <div class="fLeft label-handsome" id="userNameDiv">
                        <label>支付方式:</label>
                        <select id="payMethod" name="payMethod" style="width:90px">
                        </select>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>申请日期:</label>
                        <input id="paidStarttime" type="text" name="paidStarttime" class="easyui-datebox"
                               required="required" readonly style="width:90px"/>
                    </div>
                    <div class="fLeft label-handsome ">
                        <label>申请人:</label>
                        <input id="operater" name="operater" class="easyui-input"
                               value="<%=((SysUser)session.getAttribute("loginUser")).getUserName()%>"/>
                    </div>

                </div>
                <div class="mTop10 line-handsome">
                    <div class="fLeft label-handsome ">
                        <label>备注:</label>
                        <input id="remark" name="remark" class="easyui-input"/>
                    </div>
                    </div>
            </div>
        </form>
    </div>
    <div data-options="region:'center',border : false,title:'付款申请子项列表'">
        <table id="subItem"></table>
    </div>
</div>